package com.tmall.wireless.virtualviewdemo.utils.imageloader.utils;

import ohos.app.Context;
import ohos.bundle.IBundleManager;

import java.io.File;

public class StorageUtils {
    private static final String EXTERNAL_STORAGE_PERMISSION = "ohos.permission.WRITE_USER_STORAGE";
    private static final String INDIVIDUAL_DIR_NAME = "uil-images";

    private StorageUtils() {
    }


    public static File getCacheDirectory(Context context) {
        return getCacheDirectory(context, true);
    }


    public static File getCacheDirectory(Context context, boolean preferExternal) {
        File appCacheDir = null;

        appCacheDir = context.getCacheDir();

        return appCacheDir;
    }


    public static File getIndividualCacheDirectory(Context context) {
        return getIndividualCacheDirectory(context, INDIVIDUAL_DIR_NAME);
    }


    public static File getIndividualCacheDirectory(Context context, String cacheDir) {
        File appCacheDir = getCacheDirectory(context);
        File individualCacheDir = new File(appCacheDir, cacheDir);
        if (!individualCacheDir.exists()) {
            if (!individualCacheDir.mkdir()) {
                individualCacheDir = appCacheDir;
            }
        }
        return individualCacheDir;
    }


    public static File getOwnCacheDirectory(Context context, String cacheDir) {
        File appCacheDir = null;

        appCacheDir = context.getCacheDir();
        return appCacheDir;
    }


    public static File getOwnCacheDirectory(Context context, String cacheDir, boolean preferExternal) {
        File appCacheDir = null;

        appCacheDir = context.getCacheDir();
        return appCacheDir;
    }


    private static boolean hasExternalStoragePermission(Context context) {
        int perm = context.verifySelfPermission(EXTERNAL_STORAGE_PERMISSION);
        return perm == IBundleManager.PERMISSION_GRANTED;
    }
}
